import 'package:ai_data_capture/bean/FlowBean.dart';
import 'package:ai_data_capture/req/network_service.dart';
import 'package:ai_data_capture/widget/dialog.dart';

class FlowApi {
  static Future<List<FlowBean>> getFlow() async {
    var res = await NetworkService.post(url: 'flow/get_flow_list', map: {});
    return res?.getTypedList((map) => FlowBean.fromJson(map)) ?? [];
  }

  static runFlow(num? flowId) async {
    await NetworkService.post(url: 'flow/run_flow', map: {"flow_id": flowId});
  }

  static updateFlow(AddFlowBean res, {num? id}) async {
    Map<String, dynamic> map = {
      "description": res.description,
      "step": res.step,
    };
    if (id != null) {
      map['id'] = id;
    }
    print(map);
    await NetworkService.post(url: 'flow/update_flow', map: map);
  }

  static removeFlowById(num? id) async {
    await NetworkService.post(url: 'flow/delete_flow', map: {
      "id": id,
    });
  }

  static Future<FlowBean?> getFlowById(String? flowId) async {
    var res = await NetworkService.post(
        url: 'flow/get_flow_by_id', map: {"id": flowId});
    return res?.getTypedData((m) => FlowBean.fromJson(m));
  }
}
